/*
  S.M.A.C.K - An operating system kernel
  Copyright (C) 2010,2011 Mattias Holm and Kristian Rietveld
  For licensing and a full list of authors of the kernel, see the files
  COPYING and AUTHORS.
*/

#include <libc-private.h>
#include <syscalls.h>

/* To be defined by an application obviously. */
int main(int argc, char **argv);

/* FIXME: Ideally have this in a header shared with the kernel. */
#define PAGE_SIZE 4096

#define SVC_STACK_SIZE   (2*PAGE_SIZE)
#define STACK_BOTTOM (0x8000000 - (SVC_STACK_SIZE + PAGE_SIZE))
#define STACK_SIZE   (32*PAGE_SIZE)
#define STACK_TOP    (STACK_BOTTOM - STACK_SIZE)
#define ARGV_PAGE    (STACK_TOP - 2 * PAGE_SIZE)

#define MAX_ARGS 32

void _start(void)
{
  int argc = 1;
  char *arg_page = (char*)ARGV_PAGE;
  // Don't waste stack space...
  static char *argv[MAX_ARGS];

  argv[0] = arg_page;

  stdio_init();
  int res = main(argc, argv);
  exit(res);
}
